package com.bitoon.basketdudes.web.jpa;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name = "ranking_network", schema="rankings")
@NamedQueries({
    //@NamedQuery(name = "RankingNetwork.findAll", query = "SELECT r FROM RankingNetwork r"),
    //@NamedQuery(name = "RankingNetwork.findByIdUsuario", query = "SELECT r FROM RankingNetwork r, EquipoRanking er, Network n WHERE r.rankingNetworkPK.equipoId = er.id AND r.rankingNetworkPK.networkId = n.id AND (er.usuario.id = :idUsuario OR n.creador = :idUsuario)"),
    //@NamedQuery(name = "RankingNetwork.findByIdUsuarioAndNetworkId", query = "SELECT r FROM RankingNetwork r WHERE r.rankingNetworkPK.networkId = :idNetwork AND r.rankingNetworkPK.equipo.usuario.id = :idUsuario ORDER BY r.rankingNetworkPK.equipo.nombre")
    @NamedQuery(name = "RankingNetwork.findByIdUsuarioAndNetworkId", query = "SELECT r FROM RankingNetwork r WHERE r.rankingNetworkPK.networkId = :idNetwork AND r.equipo.usuario.id = :idUsuario"),
    @NamedQuery(name = "RankingNetwork.findByEquipoId", query = "SELECT r FROM RankingNetwork r WHERE r.equipo.id = :idEquipo order by r.posicion")
    /*
    @NamedQuery(name = "RankingNetwork.findByNetworkId", query = "SELECT r FROM RankingNetwork r WHERE r.rankingNetworkPK.networkId = :networkId"),
    @NamedQuery(name = "RankingNetwork.findByEquipoId", query = "SELECT r FROM RankingNetwork r WHERE r.rankingNetworkPK.equipoId = :equipoId"),
    @NamedQuery(name = "RankingNetwork.findByPosicion", query = "SELECT r FROM RankingNetwork r WHERE r.posicion = :posicion"),
    @NamedQuery(name = "RankingNetwork.findByAntPosicion", query = "SELECT r FROM RankingNetwork r WHERE r.antPosicion = :antPosicion")
     * 
     */
})

public class RankingNetwork implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    protected RankingNetworkPK rankingNetworkPK;

    @Basic(optional = false)
    @Column(name = "posicion")
    private int posicion;

    @Basic(optional = false)
    @Column(name = "ant_posicion")
    private int antPosicion;

    @JoinColumn(name = "network_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(fetch=FetchType.EAGER, optional = false)
    private Network network;

    @JoinColumn(name = "equipo_id", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(fetch=FetchType.EAGER, optional = false)
    private EquipoRankingNetwork equipo;

    public RankingNetwork() {
    }

    public RankingNetwork(RankingNetworkPK rankingNetworkPK) {
        this.rankingNetworkPK = rankingNetworkPK;
    }

    public RankingNetwork(RankingNetworkPK rankingNetworkPK, int posicion, int antPosicion) {
        this.rankingNetworkPK = rankingNetworkPK;
        this.posicion = posicion;
        this.antPosicion = antPosicion;
    }

    public RankingNetwork(int networkId, int equipoId) {
        this.rankingNetworkPK = new RankingNetworkPK(networkId, equipoId);
    }

    public RankingNetworkPK getRankingNetworkPK() {
        return rankingNetworkPK;
    }

    public void setRankingNetworkPK(RankingNetworkPK rankingNetworkPK) {
        this.rankingNetworkPK = rankingNetworkPK;
    }

    public int getPosicion() {
        return posicion;
    }

    public void setPosicion(int posicion) {
        this.posicion = posicion;
    }

    public int getAntPosicion() {
        return antPosicion;
    }

    public void setAntPosicion(int antPosicion) {
        this.antPosicion = antPosicion;
    }

    public Network getNetwork() {
        return network;
    }

    public void setNetwork(Network network) {
        this.network = network;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (rankingNetworkPK != null ? rankingNetworkPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof RankingNetwork)) {
            return false;
        }
        RankingNetwork other = (RankingNetwork) object;
        if ((this.rankingNetworkPK == null && other.rankingNetworkPK != null) || (this.rankingNetworkPK != null && !this.rankingNetworkPK.equals(other.rankingNetworkPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.bitoon.basketdudes.web.jpa.RankingNetwork[rankingNetworkPK=" + rankingNetworkPK + ", Posicion =" + posicion + "]";
    }

    public EquipoRankingNetwork getEquipo() {
        return equipo;
    }

    public void setEquipo(EquipoRankingNetwork equipo) {
        this.equipo = equipo;
    }

}
